package cn.wsxiot.dao;

import cn.wsxiot.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 用户数据库方法
 */
public class UserDao {

    /**
     * 登录
     * @param uemail
     * @param upasswd
     * @return
     */
    public boolean login(String uemail, String upasswd){
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rss = null;
        boolean ret = false;
        try {
            String sql = "select count(*) from user where uemail=? and upasswd=?";
            conn = DBUtil.getConnection();
            if(conn == null){
                return ret;
            }
            System.out.println("数据库连接成功");
            ps = conn.prepareStatement(sql);
            ps.setString(1, uemail);
            ps.setString(2, upasswd);
            rss = ps.executeQuery();
            rss.next();
            if(rss.getInt(1) > 0){
                ret = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }
}
